#ifndef __ARCH_UM_INCLUDE_ARCH_H__
#define __ARCH_UM_INCLUDE_ARCH_H__

#ifndef __NR_mmap
#define __NR_mmap		 90
#define __NR_munmap      91
#define __NR_nanosleep   162
#endif

#ifndef __ASSEMBLER__

/* Copied from the original x86.h */
#define do_div(n, base) ({										\
	unsigned long __upper, __low, __high, __mod, __base;		\
	__base = (base);											\
	asm("" : "=a" (__low), "=d" (__high) : "A" (n));			\
	__upper = __high;											\
	if (__high != 0) {											\
		__upper = __high % __base;								\
		__high = __high / __base;								\
	}															\
	asm("divl %2" : "=a" (__low), "=d" (__mod)					\
	    : "rm" (__base), "0" (__low), "1" (__upper));			\
	asm("" : "=A" (n) : "a" (__low), "d" (__high));				\
	__mod;														\
 })

static inline long stub_syscall0(long syscall) __attribute__((always_inline));
static inline long stub_syscall1(long syscall, long arg1) __attribute__((always_inline));
static inline long stub_syscall2(long syscall, long arg1, long arg2) __attribute__((always_inline));
static inline long stub_syscall3(long syscall, long arg1, long arg2,
								 long arg3) __attribute__((always_inline));
static inline long stub_syscall4(long syscall, long arg1, long arg2,
								 long arg3, long arg4) __attribute__((always_inline));
static inline long stub_syscall5(long syscall, long arg1, long arg2,
								 long arg3, long arg4, long arg5) __attribute__((always_inline));


/* syscall wrappers. copied from arch/um/sys-i386/shared/sysdep/stub.h */
static inline long stub_syscall0(long syscall)
{
	long ret;
	__asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall));
	return ret;
}

static inline long stub_syscall1(long syscall, long arg1)
{
	long ret;
	__asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1));
	return ret;
}

static inline long stub_syscall2(long syscall, long arg1, long arg2)
{
	long ret;
	__asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
			"c" (arg2));
	return ret;
}

static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
{
	long ret;
	__asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
			"c" (arg2), "d" (arg3));
	return ret;
}

static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
				 long arg4)
{
	long ret;
	__asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
			"c" (arg2), "d" (arg3), "S" (arg4));
	return ret;
}

static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
				 long arg4, long arg5)
{
	long ret;
	__asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
			"c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5));
	return ret;
}

static inline void trap_myself(void)
{
	__asm("int3");
}

struct mmap_arg_struct {
	unsigned long addr;
	unsigned long len;
	unsigned long prot;
	unsigned long flags;
	unsigned long fd;
	unsigned long offset;
};

#endif  /* !__ASSEMBLER__ */

#endif  /* !__ARCH_UM_INCLUDE_ARCH_H__ */
